package com.myproject.music.service.impl;
import com.myproject.music.BizException;
import com.myproject.music.domain.Song;
import com.myproject.music.mapper.SongMapper;
import com.myproject.music.service.SongService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SongServiceImpl  implements SongService {
    private static final Logger log = LoggerFactory.getLogger(SongServiceImpl.class);
    @Autowired
    private SongMapper songMapper;

    @Override
    public List<Song> selectSongAll() {
        return songMapper.selectSongAll();
    }

    @Override
    public Song selectSongById(Long id) {
        Song song =songMapper.selectSongById(id);
        if(song ==null){
            log.error("该歌曲"+id+"不存在");
            throw new BizException("该歌曲"+id+"不存在");
        }
        log.info("查询歌曲"+id+"成功");
        return songMapper.selectSongById(id);
    }

    @Override
    public List<Song> selectSongByParam(String songName) {
        return songMapper.selectSongByParam(songName);
    }

    @Override
    public List<Song> selectCreatorByParam(String creator) {
        return songMapper.selectCreatorByParam(creator);
    }

    @Override
    public int insertSong(Song song) {
        return songMapper.insertSong(song);
    }

    @Override
    public int updateSong(Song song) { return songMapper.updateSong(song); }

    @Override
    public int deleteSongById(Long id) {
        return songMapper.deleteSongById(id);
    }
}
